<template>
	<scroll-view class="list-scroll" scroll-y @scrolltolower="getList()" @refresherrefresh="getList(true)"
		:refresher-enabled="true" :refresher-triggered="refresherTriggered">
		<view class="box-list">
			<view class="box-item">
				<view class="label">
					<view class="img-icon" type="info"></view>{{typeArr[formData.type].title}}
				</view>
				<view class="items">
					<view class="item" v-for="(item,index) in list" :key="index"
						@click="$goBack('./detail?id='+item.id)">
						<view class="item-top">
							<text class="title">{{item.rsName}}</text>
							<text class="num">{{item.fileNo}}</text>
						</view>
						<view class="item-bottom">
							<text class="dept">{{orgObj[item.releaseOrgan]}}</text>
							<text class="date">{{item.modifyDate}}</text>
							<view class="img-icon" type="folder"></view>
						</view>
					</view>
				</view>
			</view>
			<empty-waybill v-show="list.length==0&&!loading"></empty-waybill>
			<view class="get-more" v-show="andMore">
				加载中<text class="uni-icon">&#xe465;</text>
			</view>
			<view class="get-more" v-show="!andMore&&list.length">
				<text>没有更多了</text>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	import emptyWaybill from "@/components/tool-empty/waybill";
	export default {
		components: {
			emptyWaybill
		},
		data() {
			return {
				typeArr: [{
						type: 1,
						title: '法律'
					},
					{
						type: 2,
						title: '行政法规'
					},
					{
						type: 3,
						title: '部门规章'
					},
					{
						type: 4,
						title: '标准规范'
					},
					{
						type: 5,
						title: '行政规范'
					},
				],
				refresherTriggered: false,
				loading: false,
				list: [],
				pages: {
					size: 20, // 每次加载的数量
					current: 1, // 记录当前页
					total: '', // 记录总数
				},
				formData: {},
				orgObj: {},
			}
		},
		computed: {
			andMore() {
				// 计算是否还有更多
				return this.pages.total !== this.list.length;
			}
		},
		methods: {
			// 加载，刷新
			getList(isRefresh) {
				if(this.loading){return;}
				if (isRefresh) {
					this.pages.current = 1;
					this.list = [];
					this.refresherTriggered = true;
					this.$nextTick(() => {
						this.refresherTriggered = false;
					})
				} else {
					if (this.andMore) {
						this.pages.current++;
					} else {
						return;
					}
				}
				this.loading = true;

				const formData = {
					...this.formData,
					...this.pages
				}
				// console.log(formData);
				this.$api.policyKnowPage(formData).then(res => {
					this.loading = false;
					const resData = res.data.data;
					this.list.push(...resData.records);
					this.pages.total = resData.total;
				})
			},
		},
		onLoad() {
			this.formData = this.$store.getters.getTempData;
			this.$api.getDict({
				code: 'release_organ',
			}).then(res => {
				const resData = res.data.data[0].children;
				resData.forEach(item => {
					this.orgObj[item.dictKey] = item.dictValue
				})

				// 获取搜索结果
				this.getList(true);
			})
		}
	}
</script>

<style lang="scss">
	@keyframes myMove {
		from {
			transform: rotate(0)
		}

		to {
			transform: rotate(360deg);
		}
	}

	.get-more {
		padding: 20rpx;
		text-align: center;
		font-size: 28rpx;

		.uni-icon {
			vertical-align: middle;
			margin-left: 20rpx;
			font-size: 40rpx;
			animation: myMove 2s linear infinite;
		}
	}

	.list-scroll ::v-deep {
		height: 100vh;
		padding: 20rpx 0;
		box-sizing: border-box;
	}

	.box-list {
		padding: 14rpx 34rpx;

		.box-item {
			background-color: #fff;
			border-radius: 10rpx;
			margin-bottom: 30rpx;
			box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.16);

			.label {
				font-size: 28rpx;
				color: #333;
				line-height: 30rpx;
				height: 30rpx;
				padding: 26rpx;
				display: flex;
				align-items: center;
				border-bottom: 1px solid #F0F0F0;


				.img-icon {
					margin-right: 10rpx;
				}
			}

			.items {
				padding: 14rpx 28rpx;

				.item {
					padding: 10rpx;
					border-bottom: 1rpx solid #F0F0F0;

					&:last-child {
						border-bottom: 0;
					}

					.item-bottom,
					.item-top {
						display: flex;
						line-height: 60rpx;
					}

					.title {
						font-size: 32rpx;
						color: #333333;
						flex: 1;
						min-width: 60%;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.num {
						color: #CA2828;
						font-size: 24rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.img-icon {
						font-size: 38rpx;
						vertical-align: middle;
					}

					.dept {
						color: #333333;
						font-size: 24rpx;
					}

					.date {
						color: #999999;
						font-size: 24rpx;
						flex: 1;
						padding-left: 30rpx;
					}
				}

			}
		}
	}
</style>
